import init, { YnStorage, YnCookie } from 'wasm';
await init();
import { App } from "vue";

import config, { StorageOptions } from '@/config/config'

/** 本地存储  LocalStorage */
export let LocalStorage: YnStorage = new YnStorage(config.localOptions)
/** 本地会话  SessionStorage */
export let SessionStorage: YnStorage = new YnStorage(config.sessionOptions)
/** Cookie  Cookie */
export let Cookie: YnCookie = new YnCookie()

export const local = {
  install: function (app: App<Element>, options: StorageOptions) {
    app.config.globalProperties[`$${options.name}`] = new YnStorage(options);
    return app
  }
}

export const session = {
  install: function (app: App<Element>, options: StorageOptions) {
    app.config.globalProperties[`$${options.name}`] = new YnStorage(options);
    return app
  }
}

export const cookie = {
  install: function (app: App<Element>) {
    app.config.globalProperties.$ck = new YnCookie();
    return app
  }
}

const _default = {
  install: function (app: App<Element>) {
    app.config.globalProperties.$ls = LocalStorage;
    app.config.globalProperties.$ss = SessionStorage;
    app.config.globalProperties.$ck = Cookie;
    return app
  }
}

export default _default